﻿@inject IHttpService _httpService
@inject NavigationManager NavigationManager
@inject IDataCacheService _dataCacheService
@inject IJSRuntime JS


<CnGalWebSite.Components.Containers.MasaTitleContainer Title="最新动态" Icon="@IconType.News.ToIconString()" OnClickMore="OnClickMore" Class="mb-2" Outline SectionId="cv-news">
     @foreach (var item in Model.Take(MaxCount))
    {
        <MDCard Class="item">
            <a href="@($"/entries/index/{item.GroupId}")">
                <img src="@item.Image" alt="@item.Title" />
            </a>
            <a class="content" @onclick="@(()=>OnClickNews(item))" href="@(string.IsNullOrWhiteSpace(item.Link) ? ("/articles/index/" + item.ArticleId) : item.Link)" target="@(string.IsNullOrWhiteSpace(item.Link)?"":"_blank")">
                <div class="head">
                    <div class="name text-truncate-1">@item.Title</div>
                    <div class="time">@item.Time.ToTimeFromNowString()</div>
                </div>
                <div class="text text-truncate-1 label-large">@item.Text</div>
            </a>
        </MDCard>
    }
</CnGalWebSite.Components.Containers.MasaTitleContainer>
<CnGalWebSite.Shared.MasaComponent.Shared.Components.TrackEvent @ref="trackEven" />


@code {
    [Parameter]
    public List<HomeNewsAloneViewModel> Model { get; set; } = new List<HomeNewsAloneViewModel>();
    [Parameter]
    public int MaxCount { get; set; } = 6;
    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }
    CnGalWebSite.Shared.MasaComponent.Shared.Components.TrackEvent trackEven;

    public async Task OnClickNews(HomeNewsAloneViewModel model)
    {
        if (trackEven != null)
        {
            await trackEven.SendTrackEvent(TrackEventType.Click, TrackEventDataType.News, model.ArticleId.ToString(), model.Text);
        }
    }

    public void OnClickMore()
    {
        NavigationManager.NavigateTo("/articles/news");

    }

}
